import redis
from PyCmpltrtok.common import get_now_string_short

redisDb = redis.Redis('localhost', 6379, 0)
r = redisDb.set('key_test002', 'test002_value')
print('set r:', r)

# https://stackoverflow.com/questions/26994666/is-there-any-guide-on-using-redis-for-fifo-job-queuing
# The idea is to add commands to the queue using LPUSH, then having the other machine RPOP them (or BRPOP) when it starts processing them.
# https://redis.io/commands/rpoplpush/

# redis> RPUSH mylist "one"
# (integer) 1
# redis> RPUSH mylist "two"
# (integer) 2
# redis> RPUSH mylist "three"
# (integer) 3
# redis> RPOPLPUSH mylist myotherlist
# "three"
# redis> LRANGE mylist 0 -1
# 1) "one"
# 2) "two"
# redis> LRANGE myotherlist 0 -1
# 1) "three"
# redis>
for _ in range(3):
    r = redisDb.lpush('list001', ('我是' + get_now_string_short()).encode('utf-8'))
    print('lpush r:', _, r)

xlist = redisDb.lrange('list001', 0, -1)
print('xlist', xlist)

elx1 = redisDb.rpop('list001')
print('el x1:', elx1.decode('utf-8'))

elx1 = redisDb.rpop('list001')
print('el x1:', elx1)

xlist = redisDb.lrange('list001', 0, -1)
print('xlist', xlist)
